# 这是一个LCD显示内容的方法
import time
import LCD1602_I2C as LCD
import temp


# 这是一个显示时间的方法
def show_time():
    now = time.strftime('%m/%d %H:%M:%S', time.localtime(time.time()))
    LCD.print_lcd(1, 1, now)
    time.sleep(0.2)


# 显示年份
def show_wYear():
    this_year = time.strftime('%Y', time.localtime(time.time()))
    LCD.print_lcd(0, 0, this_year)
    return this_year


# 显示星期
def show_wDay():
    today = time.strftime('%w', time.localtime(time.time()))
    if int(today) == 0:
        today = "Sun "
    elif int(today) == 1:
        today = "Mon "
    elif int(today) == 2:
        today = "Tues"
    elif int(today) == 3:
        today = "Wed "
    elif int(today) == 4:
        today = "Thur"
    elif int(today) == 5:
        today = "Fri "
    elif int(today) == 6:
        today = "Sat "
    LCD.print_lcd(5, 0, today)
    return today


# 背景灯自动亮的时间
def show_light_time():
    """
    这是一个按月来关闭背景灯的方法
    4——9月 6点到18点 关
    10——次年3月 7点到19点 关
    :return:
    """
    if 4 <= int(time.strftime('%m', time.localtime(time.time()))) < 10:
        if 6 <= int(time.strftime('%H', time.localtime(time.time()))) <= 18:
            LCD.turn_light(0)
        else:
            LCD.turn_light(1)
    else:
        if 7 <= int(time.strftime('%H', time.localtime(time.time()))) <= 19:
            LCD.turn_light(0)
        else:
            LCD.turn_light(1)


# 显示温度
def show_temp():
    url = "http://www.weather.com.cn/weather1d/101190402.shtml"
    # url = "http://www.weather.com.cn/weather1d/10106030301A.shtml"
    today_temp = temp.get_weather(url)
    if len(today_temp) < 7:
        today_temp = today_temp + "°C "
    elif len(today_temp) < 6:
        today_temp = today_temp + "°C  "
    else:
        today_temp = today_temp + "°C"
    LCD.print_lcd(9, 0, today_temp)
